
public class BankTest {
    public static void main(String[] args) {


    Bank bank1 = Bank.getInstanance();
    Bank bank2 = Bank.getInstanance();
    System.out.println(bank1 == bank2);

}
 }

 //饿汉式
class Bank{
    //1.类的构造器私有化
    private Bank(){

    };

    //2.在类的内部创建当前类的实例
    private static Bank  instance = new Bank();

    //3.提供私有属性的get方法,获取当前instance实例,必须为static的
    public static Bank getInstanance(){            //不能通过方法调instance,只能通过类调,故static一下
        return instance;
    }
}
